package rss;

import java.util.StringTokenizer;

public class Item
{
	private String title;
	private String description;
	private String pubDate;
	private String link;
	private String guid;
	private Enclosure enclosure;
	private String duration;
	
	
	public String getTitle()
	{
		return title;
	}
	
	public void setTitle(String title)
	{
		this.title = title;
	}
	public String getDescription()
	{
		return description;
	}
	public void setDescription(String description)
	{
		this.description = description;
	}
	public String getPubDate()
	{
		return pubDate;
	}
	public void setPubDate(String pubDate)
	{
		this.pubDate = pubDate;
	}
	public String getLink()
	{
		return link;
	}
	public void setLink(String link)
	{
		this.link = link;
	}
	public String getGuid()
	{
		return guid;
	}
	public void setGuid(String guid)
	{
		this.guid = guid;
	}
	public Enclosure getEnclosure()
	{
		return enclosure;
	}
	
	public void setEnclosure(Enclosure enc)
	{
		this.enclosure = enc;
	}

	public void setDuration(String s)
	{
		this.duration = s;
	}
	
	public String getDuration()
	{
		return this.duration;
	}
	
	public Integer getDurationInSeconds()
	{
		if (this.duration == null)
		{
			return null;
		}
		
		try
		{
			StringTokenizer tokenizer = new StringTokenizer(this.duration, ":");
			if (tokenizer.countTokens() == 0)
			{
				return null;
			}
			else
			{
				int tokens[] = new int[tokenizer.countTokens()];
				for (int i = 0; i < tokens.length; i++)
				{
					tokens[i] = Integer.parseInt(tokenizer.nextToken());
				}
				
				int seconds = 0;
				int minutes = 0;
				int hours = 0;
				
				if (tokens.length == 1)
				{
					hours = 0;
					minutes = 0;
					seconds = tokens[0];
				}
				else if (tokens.length == 2)
				{
					hours = 0;
					minutes = tokens[0];
					seconds = tokens[1];
				}
				else if (tokens.length == 3)
				{
					hours = tokens[0];
					minutes = tokens[1];
					seconds = tokens[2];
				}
				
				int result = (hours * 60 * 60) + (minutes * 60) + seconds;
				
				if (result <= 0)
				{
					return null;
				}
				else
				{
					return result;
				}
				
			}
		}
		catch (Exception e)
		{
			return null;
		}
	}
}
